home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
LISTMANA
/
__TESTER
/
FILELIST.C
next >
Wrap
Text File
|
1989-06-25
|
7KB
|
304 lines
/**** */
/**** List Testing Code version 1.0 (beta) */
/**** */
/**** All portions of this source code are the property of Jack */
/**** Herrington. I, Jack Herrington, give you permission to use */
/**** use or alter the code in any way that pleases you. You must */
/**** however return by whatever means avaliable any improvements */
/**** you believe significant to Jack Herrington, accepting that */
/**** these improvements might be contained in later releases of */
/**** the code. I also grant you permission to remove this header */
/**** from any file you are WORKING on, as long as you put it back */
/**** when you're stopped WORKING on it. */
/**** */
/**** Jack Herrington: University Of Miami, Biomedical Computing */
/**** 1600 N.W. 10th Ave. (R-53) */
/**** (305) 547-6538 */
/**** */
/****/
/**** File List Handler */
/****/
#include "ListManager.h"
#include "Tester.h"
#include "FileList.h"
/****/
/**** File List main dispersion routine */
/****/
void FileListHandler(mess,data)
int mess;
unsigned char *data;
{
switch(mess)
{
case MESS_NEW: FileListHandlerNew(); break;
case MESS_HIT: FileListHandlerHit((int *)data); break;
case MESS_CLOSE: FileListHandlerClose(); break;
case MESS_ACTIVATE: FileListHandlerActivate(1); break;
case MESS_DEACTIVATE: FileListHandlerActivate(0); break;
case MESS_UPDATE: DrawFakeGrow(Windows[CurWindow].window); break;
case MESS_GROW: FileListHandlerGrow(); break;
}
}
/****/
/**** Respond to a new message */
/****/
void FileListHandlerNew()
{
FileWindowInfo *fwi;
/**** Create the dialog */
if ( TesterDialogNew(1001,CurHandler) == (-1) ) return;
SetPort(Windows[CurWindow].window);
/**** Allocate the window record */
TesterAllocateWindowData((long)sizeof(FileWindowInfo));
TesterLockWindowInfo();
fwi = (FileWindowInfo *)TesterGetWindowInfo();
/**** Setup the window */
FileListHandlerSetupList(fwi);
/**** Unlock the window information and leave */
TesterUnLockWindowInfo();
}
/****/
/**** Setup the list */
/****/
void FileListHandlerSetupList(fwi)
FileWindowInfo *fwi;
{
Handle item;
Point cellSize,cell;
Rect box,dBox;
char charTmp[255];
int type,x,y,fold;
/**** Get the file and folder icons */
if ( ( fwi->folderIcon = (PicHandle)GetNamedResource('PICT',"\PFolderIcon") ) == 0L ) return;
DetachResource(fwi->folderIcon);
if ( ( fwi->fileIcon = (PicHandle)GetNamedResource('PICT',"\PFileIcon") ) == 0L ) return;
DetachResource(fwi->fileIcon);
/**** Get the box for the list */
GetDItem(Windows[CurWindow].window,ListBox,&type,&item,&box);
SetDItem(Windows[CurWindow].window,ListBox,type,
FileListHandlerUpdate,&box);
/**** Move up for the scrollbar and right to fill out the window */
box.top--;
box.right+=2;
/**** Create the data bounds */
dBox.left = 0; dBox.right = MAX_X;
dBox.top = 0; dBox.bottom = MAX_Y;
cellSize.h = 80; cellSize.v = 15;
/**** Create the list */
fwi->nlh = ListNew(&box,&dBox,cellSize,0,
Windows[CurWindow].window,0,1,0,1);
/**** Setup global cell definitions */
ListSetFrameWidth(0,0,fwi->nlh);
ListSetGlobalBox(0,fwi->nlh);
ListSetGlobalFont(0,0,0,fwi->nlh);
ListSetScrollMethod(incMethod,fwi->nlh);
ListSetColumnWidth(0,20,fwi->nlh);
ListSetColumnWidth(1,400,fwi->nlh);
ListSetAddative(-1,-1,fwi->nlh);
/**** Set the cells */
fold = 0;
for(y=0;y<MAX_Y;y++)
{
cell.v = y;
cell.h = 0;
ListSetHandler(PictureHandler,cell,fwi->nlh);
if ( fold == 1 )
{
ListSetData((Handle)fwi->folderIcon,cell,fwi->nlh);
fold = 0;
}
else
{
ListSetSelectable(FALSE,cell,fwi->nlh);
ListSetData((Handle)fwi->fileIcon,cell,fwi->nlh);
cell.h = 1;
ListSetSelectable(FALSE,cell,fwi->nlh);
fold = 1;
}
cell.h = 1;
(void)sprintf(charTmp,"%d",y+1);
ListSetCell((unsigned char *)charTmp,strlen(charTmp),cell,fwi->nlh);
ListSetHandler(TextBoxHandler,cell,fwi->nlh);
}
/**** Setup the flags */
ListSetEhancedFlags((NoTrackOutside),fwi->nlh);
ListDoDraw(TRUE,fwi->nlh);
}
/****/
/**** Draw the list */
/****/
pascal void FileListHandlerUpdate(Window,ItemNumber)
WindowPtr Window;
int ItemNumber;
{
FileWindowInfo *fwi;
/**** Lock the window information and update */
SetPort(Window);
TesterLockWindowInfoWindow(Window);
fwi = (FileWindowInfo *)TesterGetWindowInfoIndirect(Window);
ListUpdateWhole(fwi->nlh);
TesterUnLockWindowInfoWindow(Window);
}
/****/
/**** Hit in the window */
/****/
void FileListHandlerHit(hit)
int *hit;
{
FileWindowInfo *fwi;
Point cell,lpt;
Rect sizeArea;
int part;
/**** Lock the window information */
TesterLockWindowInfo();
fwi = (FileWindowInfo *)TesterGetWindowInfo();
SetPort(Windows[CurWindow].window);
/**** Disperse according to dialog hit */
if ( *hit == ListBox )
{
GetMouse(&lpt);
part = ListPart(lpt,&cell,fwi->nlh);
switch(part)
{
case inHorizScroll:
case inVertScroll:
case inCell:
ListCickEnhanced(lpt,0,fwi->nlh,ListLineDrag);
break;
}
}
/**** Unlock the window information */
TesterUnLockWindowInfo();
}
/****/
/**** Activate or DeActivate the list */
/****/
void FileListHandlerActivate(act)
int act;
{
FileWindowInfo *fwi;
DrawFakeGrow(Windows[CurWindow].window);
TesterLockWindowInfo();
fwi = (FileWindowInfo *)TesterGetWindowInfo();
ListActivate(act,fwi->nlh);
TesterUnLockWindowInfo();
}
/****/
/**** Hit in the growRegion of the window */
/****/
void FileListHandlerGrow()
{
FileWindowInfo *fwi;
Handle item;
Point MousePT;
Rect GrowRect,newRect,box;
long GrowRet;
int type;
/**** Set the port and get the mouse location */
TesterLockWindowInfo();
fwi = (FileWindowInfo *)TesterGetWindowInfo();
GetMouse(&MousePT);
LocalToGlobal(&MousePT);
/**** Drag the Window grow area */
GrowRect.top=100; GrowRect.bottom=600;
GrowRect.left=100; GrowRect.right=600;
if((GrowRet=GrowWindow(Windows[CurWindow].window,MousePT,&GrowRect))==0)return;
SizeWindow(Windows[CurWindow].window,LoWord(GrowRet),HiWord(GrowRet),0);
/**** Erase the whole thing */
newRect.right = LoWord(GrowRet); newRect.left = 0;
newRect.bottom = HiWord(GrowRet); newRect.top = 0;
EraseRect(&newRect);
InvalRect(&newRect);
/**** Create new userItem dimensions */
GetDItem(Windows[CurWindow].window,ListBox,&type,&item,&box);
box.top = (-1); box.bottom = HiWord(GrowRet);
box.left = 0; box.right = LoWord(GrowRet)+2;
SetDItem(Windows[CurWindow].window,ListBox,type,item,&box);
/**** Use ListSize to define the new list size */
ListSize(box.right-box.left,box.bottom-box.top,fwi->nlh);
/**** Unlock and leave */
TesterUnLockWindowInfo();
}
/****/
/**** Close up the window */
/****/
void FileListHandlerClose()
{
FileWindowInfo *fwi;
TesterLockWindowInfo();
fwi = (FileWindowInfo *)TesterGetWindowInfo();
ListDispose(fwi->nlh);
TesterUnLockWindowInfo();
DisposHandle(fwi->folderIcon);
DisposHandle(fwi->fileIcon);
TesterKillWindow(CurWindow);
}